<template>
  <div>
    <div class="flexrowbetween flexwrapper" style="align-items:flex-start">
      <div class="flex aligncenter">
        <div class="iconbox flexcenter commhover blackbg mr_15" @click="resetQuery">
            <i class="el-icon-refresh f-20" :class="{'rotate':isrefresh}"></i>
        </div>
        <el-button size="mini" icon="el-icon-delete" class="mr_15" :disabled='multiple'>删除</el-button>
        【大转盘抽奖】的访问日志
      </div>
      <div>
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="0"
        >
          <el-form-item prop="name">
            <el-input class="searchinput"
              v-model="queryParams.name"
              placeholder="用户名/昵称/最近访问时间"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item class="mr_0">
            <el-dropdown trigger="click">
                <el-button size="mini" class="nor_border plr_9">
                  <svg-icon class-name="f-14" icon-class="listicon" />
                  <i class="el-icon-caret-bottom el-icon--right"></i>
                    <!-- <i class="el-icon-s-fold f-14"></i> -->
                </el-button>
                <el-dropdown-menu slot="dropdown">
                    <div class="dropbody">
                      <el-checkbox-group v-model="checkedOption" class="flexcolumn" @change="changeSelect">
                        <el-checkbox v-for="(item,index) in selectoptions" :label="item.label" :key="index" class="m_5">{{item.label}}</el-checkbox>
                      </el-checkbox-group>
                    </div>
                </el-dropdown-menu>
            </el-dropdown>
          </el-form-item>
          <el-form-item>
            <el-dropdown trigger="click" @command="handleCommand">
                <el-button size="mini" class="nol_border plr_9">
                  <svg-icon class-name="f-14" icon-class="export" />
                  <i class="el-icon-caret-bottom el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="(item,index) in exportlist" :key="index" :command="item.id">{{item.name}}</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
          </el-form-item>
          <el-form-item>
            <el-button class="f-14"
              type=""
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            ></el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <el-table
        v-loading="loading"
        :data="list"
        border
        ref="tablelayout"
        class="commtable"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column v-if="activelogOption.includes('ID')" label="ID" prop="id" width="80" align="center"/>
        <el-table-column v-if="activelogOption.includes('openid')" label="openid" prop="openid" width="100" align="center"/>
        <el-table-column v-if="activelogOption.includes('活动ID')" label="活动ID" prop="name" width="100" align="center"/>
        <el-table-column v-if="activelogOption.includes('活动名称')" label="活动名称" prop="name" width="200" align="center"/>
        <el-table-column v-if="activelogOption.includes('访问次数')" label="访问次数" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.num }} 3 次</span>
          </template>
        </el-table-column>
        <el-table-column v-if="activelogOption.includes('头像')" label="头像" width="150" align="center">
          <template slot-scope="scope">
            <img src="@/assets/images/icon1.png" class="imgmini"/>
            <span>{{ scope.row.status }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="activelogOption.includes('昵称')" label="昵称" width="150" align="center">
          <template slot-scope="scope">
            <span>昵称{{ scope.row.status }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="activelogOption.includes('IP')" label="IP" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.ip }} 218.58.62.168 </span>
          </template>
        </el-table-column>
        <el-table-column v-if="activelogOption.includes('最近访问时间')" label="最近访问时间" align="center" width="160">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.num"
        @pagination="getList"
      />
  </div>
</template>
<script>
import { mapState } from 'vuex';
export default {
  data() {
    return {
      queryParams: {
        page: 1,
        num: 10,
        name: undefined,
      },
      total:1,
      loading:false,
      list:[{id:1},{id:2}],
      checkedOption:[],
      isrefresh:false,
      selectoptions:[
        {id:1,label:"ID"},
        {id:2,label:"openid"},
        {id:3,label:"活动ID"},
        {id:4,label:"活动名称"},
        {id:5,label:"访问次数"},
        {id:6,label:"头像"},
        {id:7,label:"昵称"},
        {id:8,label:"IP"},
        {id:9,label:'最近访问时间'}
      ],
      dialogVisible:false,

      // 日志
      dialoglogVisible:false,
      rowId:'',
      multiple:true,
      rowids:[]
    };
  },

  props:{
    type:{
      type:Number,
      default:1
    }
  },

  computed:{
    ...mapState({
      activelogOption:state => state.paramsoption.activelogOption,
    }),
  },

  created(){
    let activelogOption = JSON.parse(localStorage.getItem('activelogOption'));
    if(activelogOption){
      this.changeSelect(activelogOption);
    }
    this.checkedOption=this.activelogOption;
  },

  methods: {

    getList() {
      this.loading = true;
      let params = { ...this.queryParams };
      //   if(this.queryParams.type=='创建日期' && this.time && this.time.length){
      //     params.startime = this.time[0]
      //     params.endtime = this.time[1]
      //   }
      //   feedbacklist(params).then((response) => {
      //     this.tableData = response.data.list;
      //     this.total = response.data.count;
      //     this.loading = false;
      //   });
      this.isrefresh = false
      this.loading = false;
    },

    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },

    resetQuery() {
      this.isrefresh = true
      this.resetForm("queryForm");
      this.handleQuery();
    },

    changeSelect(arr){
      this.$store.commit('SET_ACTIVEOPTION',arr);
      this.$nextTick(() => { //在数据加载完，重新渲染表格
        this.$refs.tablelayout&&this.$refs.tablelayout.doLayout();
      })
    },

    // 复选框
    handleSelectionChange(rows){
        this.rowids = rows.map((item) => item.id);
        this.multiple = !rows.length
    },

    handleCommand(command) {
      console.log(command);
    },

    handleFabu(row){
      this.dialogVisible = true
    },

    handleClose(){
      this.dialogVisible = false
    },

    handleLog(row){
      this.rowId = row.id
      this.dialoglogVisible = true
    }
    
  },
};
</script>

<style lang="scss" scoped>
.iconbox {
  width: 32px;
  height: 26px;
}
.imgmini{
    width: 40px;
    height: 40px;
    margin: auto;
}
.imgbox{
    width: 120px;
    height: 120px;
}
</style>